<template>
  <view class="app-container">
    <view class="form-content">
      <!-- 申请类型选择 -->
      <view class="radio-group">
        <label class="radio-item border-section" @click="applyType = 'normal'">
          <view class="radio-custom" :class="{ checked: applyType === 'normal' }"></view>
          <span>申请返校</span>
          <span class="desc">适用于正常返校</span>
        </label>
        <label class="radio-item border-section" @click="applyType = 'delay'">
          <view class="radio-custom" :class="{ checked: applyType === 'delay' }"></view>
          <span>申请延期返校</span>
          <span class="desc">适用于特殊情况，延期返校</span>
        </label>
      </view>

      <!-- 正常返校流程 -->
      <view class="process-section border-section" v-if="applyType === 'normal'">
        <h3>请假流程</h3>
        <view>
          <!-- 第一个审批人 -->
          <view id="firstPerson">
            <view id="personInformation">
              审批人(导师)
              <view id="name">
                张三
              </view>
            </view>
            <view id="surname">
              张
            </view>
          </view>

          <!-- 会签线 -->
          <view id="line_1">
            会签--------------------1人通过即可进入下一节点
          </view>

          <!-- 第二个审批人 -->
          <view id="otherPerson">
            <view id="personInformation">
              审批人(导师)
              <view id="name">
                王贰<br>
                本月不允许继续请假<br>
                马上要考试了！
              </view>
            </view>
            <view id="surname">
              王
            </view>
          </view>
        </view>
      </view>

      <!-- 延期返校信息 -->
      <view class="delay-section border-section" v-else>
        <h3>延期返校信息</h3>
        <view class="form-item">
          <label>延期返校时间</label>
          <textarea
              v-model="delayDate"
              placeholder="请填写格式：YYYY-MM-DD（例：2024-09-15）"
          ></textarea>
        </view>
        <view class="form-item">
          <label>返校理由</label>
          <textarea
              placeholder="请输入返校理由"
              maxlength="100"
              v-model="reason"
          ></textarea>
        </view>

        <h3>返校申请流程</h3>
        <view>
          <view id="firstPerson">
            <view id="personInformation">
              审批人(导师)
              <view id="name">
                张三
              </view>
            </view>
            <view id="surname">
              张
            </view>
          </view>
          <view id="line_1">
            会签--------------------1人通过即可进入下一节点
          </view>
          <view id="otherPerson">
            <view id="personInformation">
              审批人(导师)
              <view id="name">
                王贰
              </view>
            </view>
            <view id="surname">
              王
            </view>
          </view>
          <view id="otherPerson">
            <view id="personInformation">
              审批人(学校党委副书记)
              <view id="name">
                贺磊
              </view>
            </view>
            <view id="surname">
              贺
            </view>
          </view>
        </view>
      </view>

      <button class="submit-btn" @click="submit">提交申请</button>
    </view>
  </view>
</template>

<script>
export default {
  name: "ReturnApply",
  data() {
    const today = new Date().toISOString().split("T")[0];
    return {
      applyType: "normal",
      delayDate: today,
      reason: "",
    };
  },
  methods: {
    submit() {
      const dateReg = /^\d{4}-\d{2}-\d{2}$/;
      if (this.applyType === "delay" && !dateReg.test(this.delayDate)) {
        alert("请按提示格式填写延期返校时间（例：2024-09-15）");
        return;
      }
      alert("申请已提交，等待审批");
    },
  },
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}

.app-container {
  width: 375px;
  margin: 20px auto;
  background-color: #fff;
  border: 1px solid #eee;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-content {
  padding: 15px;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
}

.radio-item {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.radio-custom {
  width: 16px;
  height: 16px;
  border: 1px solid #ccc;
  border-radius: 50%;
  margin-right: 8px;
  position: relative;
  transition: all 0.2s;
}

.radio-custom.checked {
  background-color: #007bff;
  border-color: #007bff;
}

.radio-custom.checked::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  background: #fff;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.radio-item .desc {
  font-size: 12px;
  color: #666;
  margin-left: 5px;
}

.border-section {
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 15px;
  transition: all 0.2s ease;
  margin-bottom: 18px;
}

.process-section h3,
.delay-section h3 {
  font-size: 16px;
  margin-bottom: 10px;
  color: #333;
  font-weight: 600;
  padding-bottom: 8px;
  border-bottom: 1px solid #f0f0f0;
}

/* 请假流程样式 */
#firstPerson{
  margin-left: 20px;
  margin-top: 15px;
  width: 300px;
  height: 80px;
  display: flex;
  justify-content: space-between;
}

#name{
  font-weight: 400;
  font-size: 15px;
  text-align: left;
  color: #808080;
  margin-top: 5px;
}

#surname{
  color: #f8f8f8;
  width: 58px;
  height: 58px;
  border-radius: 58px;
  text-align: center;
  font-size: 35px;
  background: #2264ff;
  margin-left: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#line_1{
  color: #8f939c;
  font-size: 13px;
  margin-left: 10px;
  margin-top: 10px;
}

#otherPerson{
  margin-top: 60px;
  margin-left: 20px;
  width: 300px;
  height: 80px;
  display: flex;
  justify-content: space-between;
}

#personInformation {
  color: #333;
  font-size: 14px;
}

.form-item {
  margin-bottom: 15px;
}

.form-item label {
  display: block;
  font-size: 14px;
  color: #666;
  margin-bottom: 5px;
}

.form-item input,
.form-item textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

.form-item textarea {
  min-height: 80px;
  resize: none;
}

.submit-btn {
  width: 100%;
  padding: 12px;
  background-color: #007bff;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.submit-btn:hover {
  background-color: #0056b3;
}
</style>